package com.bookmarket.test;

import com.bookmarket.entity.Book;
import com.bookmarket.entity.Custom;
import com.bookmarket.entity.Order;
import com.bookmarket.entity.Order_Book;
import com.bookmarket.service.LJOrderListService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.Date;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-mybatis.xml")
public class LJOrderDemo {

    @Resource
    private LJOrderListService ljOrderListService;

    @Test//测试根据地址id查询对应的地址
    public void test1(){
        System.out.println( ljOrderListService.selectById(8));
    }
    @Test//向订单表插入地址表相关信息
    public  void test2(){
        Custom c=new Custom();
        c.setId(1);
        Order o=new Order(new Date(), "框框","123564879","珠海",0,0,c);
        System.out.println(ljOrderListService.insertByOrder(o));
    }
    @Test//根据商品id查询对应的商品
    public void test3(){
        System.out.println(ljOrderListService.selectByShopId(43));
    }
    @Test//查看刚刚插入订单的主键
    public void test4(){
        Custom c=new Custom();
        c.setId(1);
        Order o=new Order(new Date(),"小明","123564879","珠海",0,0,c);
        System.out.println(ljOrderListService.selectByOrder(o));
    }
    @Test//向关系表存数据
    public void test5(){
        Custom c=new Custom();
        c.setId(1);

        Order o=new Order(new Date(),"小明","123564879","珠海",0,0,c);
        Order od=ljOrderListService.selectByOrder(o);

        Book b=new Book();
        b.setId(3);

        Order_Book ob=new Order_Book();
        ob.setOrder(od);
        ob.setBook(b);
        ob.setAmount(5);

        System.out.println(ljOrderListService.insertOrderBook(ob));
    }
    @Test//根据商品id查看book外键
    public void test6(){
        System.out.println(ljOrderListService.chaId(43));
    }
    @Test//根据地址id查看地址表中custom_id(外键值)
    public void test7(){
        System.out.println(ljOrderListService.chaAddressId(38));
    }








    public LJOrderListService getLjOrderListService() {
        return ljOrderListService;
    }

    public void setLjOrderListService(LJOrderListService ljOrderListService) {
        this.ljOrderListService = ljOrderListService;
    }
}
